home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #2 / Amiga Plus CD - 1995 - No. 2.iso / internet / faq / englisch / g++&libg++ < prev    next >
Encoding:
Text File  |  1995-04-11  |  54.2 KB  |  1,347 lines

  1. Archive-name: g++-FAQ/plain
  2. Last-modified: 01 Mar 1995
  3. Frequency: bimonthly
  4.  
  5. [ this is the plain text version, the parent is the texinfo version ]
  6.  
  7.  
  8. Preface
  9. *******
  10.  
  11.    This is a list of frequently asked questions (FAQ) for g++ users;
  12. thanks to all those who sent suggestions for improvements.  Thanks to
  13. Marcus Speh for doing the index.
  14.  
  15.    Please send updates and corrections to the FAQ to
  16. `jbuck@synopsys.com'.  Please do *not* use me as a resource to get your
  17. questions answered; that's what gnu.g++.help is for and I don't have
  18. the time to support the net's use of g++.
  19.  
  20.    Many FAQs, including this one, are available on the archive site
  21. rtfm.mit.edu, in the directory `pub/usenet/news.answers'.  This FAQ may
  22. be found in the subdirectory g++-FAQ.
  23.  
  24.    This FAQ is intended to supplement, not replace, Marshall Cline's
  25. excellent FAQ for the C++ language and for the newsgroup comp.lang.c++.
  26. Especially if g++ is the first C++ compiler you've ever used, the
  27. question "How do I do <X> with g++?" is probably really "How do I do
  28. <X> in C++?".  The C++ FAQ is not on rtfm.mit.edu for some reason; you
  29. can find it on sun.soe.clarkson.edu in `/pub/C++'.
  30.  
  31.  
  32. The latest poop
  33. ***************
  34.  
  35.    This section is intended to describe more recent changes to g++,
  36. libg++, and such.  Some things in this section will eventually move
  37. elsewhere.
  38.  
  39.  
  40. What's new in version 2.6.0 of gcc/g++
  41. ======================================
  42.  
  43.    The long-awaited version 2.6.0 of gcc/g++ (along with a matching
  44. version of libg++) have now been released, together with three bug fix
  45. releases, 2.6.1 through 2.6.3 (the latest version).  This represents a
  46. great deal of work on the part of the g++ maintainers to fix
  47. outstanding bugs and move the compiler closer to the current ANSI/ISO
  48. standards committee's working paper, including supporting some of the
  49. new features that have been added to the language.  For example:
  50.  
  51.    * built-in boolean type `bool', with constants `true' and `false'
  52.      (this will break code that uses these keywords as variable names).
  53.  
  54.    * overloaded operator for array new and delete (operator new [] and
  55.      delete []).
  56.  
  57.    * ANSI/ISO working paper-conforming lifetime of temporaries
  58.      (temporaries now live longer than they used to).
  59.  
  60.    * explicit instantiation of templates (`template class A<int>;'),
  61.      along with an option (`-fno-implicit-templates') to disable
  62.      emission of implicitly instantiated templates, obsoletes
  63.      `-fexternal-templates'.
  64.  
  65.    * static member constants (`static const int foo = 4;' within the
  66.      class declaration).
  67.  
  68.    * There is an *alpha* version of exception handling that currently
  69.      works *only* on Sparcs running SunOS 4.1.x.  Full exception
  70.      support will still take a while longer.
  71.  
  72.    * An undocumented feature: 2.6.x parses the new cast expressions
  73.      containing the keywords `static_cast', `reinterpret_cast',
  74.      `const_cast', and `dynamic_cast'.  For the time being, the first
  75.      three are silently turned into normal casts (in my opinion, a
  76.      warning should be given that they aren't completely supported).
  77.      `dynamic_cast' will yield a "sorry, not yet implemented" message,
  78.      since it requires run-time type identification support to
  79.      implement.
  80.  
  81.    Also there have been many bug fixes, in nested types, access control,
  82. pointers to member functions, the parser, templates, overload
  83. resolution, etc, etc.  Finally, `.cpp' is now supported as a C++ file
  84. extension.
  85.  
  86.    Note that g++ 2.6.x won't compile libg++ 2.5.3 (due to a bug in that
  87. version of libg++); you'll need libg++ 2.6 or later.
  88.  
  89.    Despite what the `NEWS' file in the distribution says, the original
  90. Fresco distributed with X11R6 did not quite compile, because of use of
  91. "true" and "false" that conflicts with the new bool type.  This problem
  92. was fixed in public patch #5 to X11R6, so Fresco should now build fine
  93. with g++ 2.6 provided that you have installed this patch.
  94.  
  95.  
  96. The GNU Standard C++ Library
  97. ============================
  98.  
  99.    The GNU Standard C++ Library (also called the "GNU ANSI C++ Library"
  100. in places in the code) is not libg++, though it is included in the
  101. libg++ distribution.  Rather, it will contain classes and functions
  102. required by the ANSI/ISO standard.  The copyright conditions are the
  103. same as those for for the iostreams classes; the LGPL is not used.  See
  104. *Note legalities::.
  105.  
  106.    This library, libstdc++, is in the libg++ distribution in versions
  107. 2.6.2 and later.  It requires at least gcc 2.6.1 to build.  It contains
  108. a hacked-up version of HP's implementation of the Standard Template
  109. Library (see *Note Standard Template Library::).
  110.  
  111.  
  112. Obtaining Source Code
  113. *********************
  114.  
  115.  
  116. What is the latest version of gcc, g++, and libg++?
  117. ===================================================
  118.  
  119.    The latest "2.x" version of gcc/g++ is 2.6.3, released December 1,
  120. 1994.  The latest version of libg++ is 2.6.2, released December 16,
  121. 1994.  Don't use 2.5.x, with x less than 5, for C++ code; there were
  122. some serious bugs that didn't have easy workarounds.  2.5.8 is the most
  123. solid 2.5.x release.
  124.  
  125.    For some non-Unix platforms, the latest port of gcc may be an earlier
  126. version (2.5.8, say).  You'll need to use a version of libg++ that has
  127. the same first two digits as the compiler version, e.g. use libg++
  128. 2.5.x (for the latest x you can find) with gcc version 2.5.8.
  129.  
  130.    The latest "1.x" version of gcc is 1.42, and the latest "1.x"
  131. version of g++ is 1.42.0.  While gcc 1.42 is quite usable for C
  132. programs, I recommend against using g++ 1.x except in special
  133. circumstances.
  134.  
  135.  
  136. How do I get a copy of g++ for Unix?
  137. ====================================
  138.  
  139.    First, you may already have it if you have gcc for your platform;
  140. g++ and gcc are combined now (as of gcc version 2.0).
  141.  
  142.    You can get g++ from a friend who has a copy, by anonymous FTP or
  143. UUCP, or by ordering a tape or CD-ROM from the Free Software Foundation.
  144.  
  145.    The Free Software Foundation is a nonprofit organization that
  146. distributes software and manuals to raise funds for more GNU
  147. development.  Getting your copy from the FSF contributes directly to
  148. paying staff to develop GNU software.  CD-ROMs cost $400 if an
  149. organization is buying, or $100 if an individual is buying.  Tapes cost
  150. around $200 depending on media type.  I recommend asking for version 2,
  151. not version 1, of g++.
  152.  
  153.    For more information about ordering from the FSF, contact
  154. gnu@prep.ai.mit.edu, phone (617) 876-3296 or anonymous ftp file
  155. `/pub/gnu/GNUinfo/ORDERS' from prep.ai.mit.edu or one of the sites
  156. listed below.
  157.  
  158.    Here is a list of anonymous FTP archive sites for GNU software.
  159.  
  160.      ASIA: ftp.cs.titech.ac.jp, utsun.s.u-tokyo.ac.jp:/ftpsync/prep,
  161.      cair.kaist.ac.kr:/pub/gnu, ftp.nectec.or.th:/pub/mirrors/gnu
  162.      
  163.      AUSTRALIA: archie.oz.au:/gnu (archie.oz or archie.oz.au for ACSnet)
  164.      
  165.      AFRICA: ftp.sun.ac.za:/pub/gnu
  166.      
  167.      MIDDLE-EAST: ftp.technion.ac.il:/pub/unsupported/gnu
  168.      
  169.      EUROPE: irisa.irisa.fr:/pub/gnu, ftp.univ-lyon1.fr:pub/gnu,
  170.      ftp.mcc.ac.uk, unix.hensa.ac.uk:/pub/uunet/systems/gnu, ftp.denet.dk,
  171.      src.doc.ic.ac.uk:/gnu, ftp.eunet.ch, nic.switch.ch:/mirror/gnu,
  172.      ftp.informatik.rwth-aachen.de:/pub/gnu, ftp.informatik.tu-muenchen.de,
  173.      ftp.win.tue.nl:/pub/gnu, ftp.funet.fi:/pub/gnu, ftp.stacken.kth.se,
  174.      isy.liu.se, ftp.luth.se:/pub/unix/gnu, ftp.sunet.se:/pub/gnu,
  175.      archive.eu.net
  176.      
  177.      SOUTH AMERICA: ftp.unicamp.br:/pub/gnu
  178.      
  179.      WESTERN CANADA: ftp.cs.ubc.ca:/mirror2/gnu
  180.      
  181.      USA: wuarchive.wustl.edu:/systems/gnu, labrea.stanford.edu,
  182.      ftp.digex.net:/pub/gnu, ftp.kpc.com:/pub/mirror/gnu,
  183.      f.ms.uky.edu:/pub3/gnu, jaguar.utah.edu:/gnustuff,
  184.      ftp.hawaii.edu:/mirrors/gnu, vixen.cso.uiuc.edu:/gnu,
  185.      mrcnext.cso.uiuc.edu:/pub/gnu, ftp.cs.columbia.edu:/archives/gnu/prep,
  186.      col.hp.com:/mirrors/gnu, gatekeeper.dec.com:/pub/GNU,
  187.      ftp.uu.net:/systems/gnu
  188.  
  189.    The "official site" is prep.ai.mit.edu, but your transfer will
  190. probably go faster if you use one of the above machines.
  191.  
  192.    Most GNU utilities are compressed with "gzip", the GNU compression
  193. utility.  All GNU archive sites should have a copy of this program,
  194. which you will need to uncompress the distributions.
  195.  
  196.    UUNET customers can get GNU sources from UUNET via UUCP.  UUCP-only
  197. sites can get GNU sources by "anonymous UUCP" from site "osu-cis" at
  198. Ohio State University.  You pay for the long-distance call to OSU; the
  199. price isn't too bad on weekends at 9600 bps.  Send mail to
  200. uucp@cis.ohio-state.edu or osu-cis!uucp for more information.
  201.  
  202.    OSU lines are often busy.  If you're in the USA, and are willing to
  203. spend more money, you can get sources via UUCP from UUNET using their
  204. 900 number: 1-900-GOT-SRCS (900 numbers don't work internationally).
  205. You will be billed $0.50/minute by your phone company.
  206.  
  207.    Don't forget to retrieve libg++ as well!
  208.  
  209.  
  210. Getting gcc/g++ for the HP Precision Architecture
  211. =================================================
  212.  
  213.    If you use the HP Precision Architecture (HP-9000/7xx and
  214. HP-9000/8xx) and you want to use debugging, you'll need to use the GNU
  215. assembler, GAS (version 2.3 or later).  If you build from source, you
  216. must tell the configure program that you are using GAS or you won't get
  217. debugging support.  A non-standard debug format is used, since until
  218. recently HP considered their debug format a trade secret.  Thanks to
  219. the work of lots of good folks both inside and outside HP, the company
  220. has seen the error of its ways and has now released the required
  221. information.  The team at the University of Utah that did the gcc port
  222. now has code that understands the native HP format.
  223.  
  224.    Some enhancements for the HP that haven't been integrated back into
  225. the official GCC are available from the University of Utah, site
  226. jaguar.cs.utah.edu.  You can retrieve sources and prebuilt binaries for
  227. GCC (2.6.3.u6), GDB (4.13.u4), binutils (2.5.2.u4: this includes GAS),
  228. and libg++ (2.6.2.u2); see the directory `/dist'.
  229.  
  230.    The libg++ version is actually the same as the FSF 2.6.  The Utah
  231. version of GDB can now understand both the GCC and HP C compiler debug
  232. formats, so it is no longer necessary to have two different GDB
  233. versions.
  234.  
  235.    I recommend that HP users use the Utah versions of the tools (see
  236. above), though at this point the standard FSF versions will work well.
  237.  
  238.    HP GNU users can also find useful stuff on the site geod.emr.ca in
  239. the `/pub/GNU-HP' directory.
  240.  
  241.  
  242. Getting gcc/g++ binaries for Solaris 2.x
  243. ========================================
  244.  
  245.    "Sun took the C compiler out of Solaris 2.x.  Am I stuck?"
  246.  
  247.    No; prep.ai.mit.edu and its mirror sites provide GCC binaries for
  248. Solaris.  As a rule, these binaries are not updated as often as the
  249. sources are, so if you want the very latest version of gcc/g++, you may
  250. need to grab and install binaries for an older version and use it to
  251. bootstrap the latest version from source.
  252.  
  253.    The latest gcc binaries on prep.ai.mit.edu and its mirror sites are
  254. for version 2.5.6 for Solaris on the Sparc, and version 2.4.5 for
  255. Solaris on Intel 386/486 machines.  There are also binaries for "gzip",
  256. the GNU compression utility, which you'll need for uncompressing the
  257. binary distribution.  On any GNU archive site, look in subdirectories
  258. `i486-sun-solaris2' or `sparc-sun-solaris2'.
  259.  
  260.    The ftp directory /pub/GNU on site camus.quintus.com contains various
  261. GNU and freeware programs for Solaris2.X running on the sparc. These are
  262. packaged to enable installation using the Solaris "pkgadd" utility.
  263. These include GNU emacs 19.19, gcc (and g++) 2.5.8, Perl 4.036, and
  264. others.
  265.  
  266.  
  267. How do I get a copy of g++ for (some other platform)?
  268. =====================================================
  269.  
  270.    The standard gcc/g++ distribution includes VMS support.  Since the
  271. FSF people don't use VMS, it's likely to be somewhat less solid than
  272. the Unix version.  Precompiled copies of g++ and libg++ in
  273. VMS-installable form are available by FTP from mango.rsmas.miami.edu.
  274. See also the site ftp.stacken.kth.se (in Sweden), directory
  275. /pub/GNU-VMS/contrib, which has gcc-2.5.8 and libg++-2.5.3.
  276.  
  277.    There are two different versions of gcc/g++ for MS-DOS: EMX and
  278. DJGPP.  EMX also works for OS/2 and is described later.  DJGPP is DJ
  279. Delorie's port.  It can be found on many FTP archive sites; its "home"
  280. is on oak.oakland.edu, directory `~ftp/pub/msdos/djgpp'.
  281.  
  282.    The latest version of DJGPP is 1.12.maint1.  This version runs under
  283. Windows 3.x.  It includes a port of gcc 2.6.0, plus support software.
  284.  
  285.    FSF sells floppies with DJGPP on them; see above for ordering
  286. software from the FSF.
  287.  
  288.    For information on Amiga ports of gcc/g++, retrieve the file
  289. `/pub/gnu/MicrosPorts/Amiga' from prep.ai.mit.edu, or write to Markus
  290. M. Wild <wild@nessie.cs.id.ethz.ch>, who I hope won't be too upset that
  291. I mentioned his name here.
  292.  
  293.    A port of gcc to the Atari ST can be found on the site
  294. "atari.archive.umich.edu", under `/atari/Gnustuff/Tos', along with many
  295. other GNU programs.  This version is usually the same as the latest FSF
  296. release.  See the "Software FAQ" for the Usenet group
  297. "comp.sys.atari.st" for more information.
  298.  
  299.    There are two different ports of gcc to OS/2, the so-called EMX port
  300. (which also runs on MS-DOS), and a port called "gcc/2".  The EMX port's
  301. C library attempts to provide a Unix-like environment; gcc/2 uses a
  302. rather buggy port of the BSD libc.  For more information ask around on
  303. "comp.os.os2.programmer.misc".
  304.  
  305.    The EMX port is available by FTP from
  306.  
  307.      ftp.uni-stuttgart.de(129.69.1.12) in /pub/systems/os2/emx-0.8h
  308.      src.doc.ic.ac.uk(146.169.2.1) in /pub/packages/os2/2_x/unix/gnu/emx08h
  309.      ftp.informatik.tu-muenchen.de(131.159.0.198) in
  310.              /pub/comp/os/os2/devtools/emx+gcc
  311.  
  312.    gcc/2, together with other GNUware for OS/2, can be obtained by FTP
  313. from
  314.  
  315.      ftp-os2.cdrom.com(192.153.46.2) in /pub/os2/2_x/unix/gnu
  316.      ftp-os2.nmsu.edu (128.123.35.151) in /pub/os2/2_x/unix/gnu
  317.      luga.latrobe.edu.au (131.172.2.2) in /pub/os2/2_x/unix/gnu
  318.  
  319.    The current maintainer of the gcc/2 port is Colin Jensen (Michael
  320. Johnson did the original port).  His address is cjensen@netcom.com.
  321.  
  322.    Eberhard Mattes did the EMX port.  His address is
  323. mattes@azu.informatik.uni-stuttgart.de.
  324.  
  325.    I do not have information on ports of gcc/g++ to Apple Macintosh
  326. platforms, but I understand that there are some out there (please send
  327. in pointers).  FSF is no longer boycotting Apple as the League for
  328. Programming Freedom boycott has been dropped.
  329.  
  330.  
  331. But I can only find g++-1.42!
  332. =============================
  333.  
  334.    "I keep hearing people talking about g++ 2.5.8 (or some other number
  335. starting with 2), but the latest version I can find is g++ 1.42.  Where
  336. is it?"
  337.  
  338.    As of gcc 2.0, C, C++, and Objective-C as well are all combined into
  339. a single distribution called gcc.  If you get gcc you already have g++.
  340. The standard installation procedure for any gcc version 2 compiler will
  341. install the C++ compiler as well.
  342.  
  343.    One could argue that we shouldn't even refer to "g++-2.x.y" but it's
  344. a convention.  It means "the C++ compiler included with gcc-2.x.y."
  345.  
  346.  
  347. Installation Issues and Problems
  348. ********************************
  349.  
  350.  
  351. I can't build g++ 1.x.y with gcc-2.x.y!
  352. =======================================
  353.  
  354.    "I obtained gcc-2.x.y and g++ 1.x.y and I'm trying to build it, but
  355. I'm having major problems.  What's going on?"
  356.  
  357.    If you wish to build g++-1.42, you must obtain gcc-1.42 first.  The
  358. installation instructions for g++ version 1 leave a lot to be desired,
  359. unfortunately, and I would recommend that, unless you have a special
  360. reason for needing the 1.x compiler, that C++ users use the latest
  361. g++-2.x version, as it is the version that is being actively maintained.
  362.  
  363.    There is no template support in g++-1.x, and it is generally much
  364. further away from the ANSI draft standard than g++-2.x is.
  365.  
  366.  
  367. OK, I've obtained gcc; what else do I need?
  368. ===========================================
  369.  
  370.    First off, you'll want libg++ as you can do almost nothing without it
  371. (unless you replace it with some other class library).
  372.  
  373.    Second, depending on your platform, you may need "GAS", the GNU
  374. assembler, or the GNU linker (see next question).
  375.  
  376.    Finally, while it is not required, you'll almost certainly want the
  377. GNU debugger, gdb.  The latest version is 4.13, released Aug. 14, 1994.
  378. Other debuggers (like dbx, for example) will normally not be able to
  379. understand at least some of the debug information produced by g++.
  380.  
  381.  
  382. Should I use the GNU linker, or should I use "collect"?
  383. =======================================================
  384.  
  385.    First off, for novices: special measures must be taken with C++ to
  386. arrange for the calling of constructors for global or static objects
  387. before the execution of your program, and for the calling of
  388. destructors at the end.  (Exception: System VR3 and System VR4 linkers
  389. support user-defined segments; g++ on these systems requires neither
  390. the GNU linker nor collect.  So if you have such a system, the answer
  391. is that you don't need either one).
  392.  
  393.    If you have experience with AT&T's "cfront", this function is
  394. performed there by programs named "patch" or "munch".  With GNU C++, it
  395. is performed either by the GNU linker or by a program known as
  396. "collect".  The collect program is part of the gcc-2.x distribution;
  397. you can obtain the GNU linker separately as part of the "binutils"
  398. package.  The latest version of binutils is 2.5.2, released November 2,
  399. 1994.
  400.  
  401.    (To be technical, it's "collect2"; there were originally several
  402. alternative versions of collect, and this is the one that survived).
  403.  
  404.    There are advantages and disadvantages to either choice.
  405.  
  406.    Advantages of the GNU linker:
  407.  
  408.    It's faster than using collect - collect basically runs the standard
  409. Unix linker on your program twice, inserting some extra code after the
  410. first pass to call the constructors.  This is a sizable time penalty
  411. for large programs.  The GNU linker does not require this extra pass.
  412.  
  413.    GNU ld reports undefined symbols using their true names, not the
  414. mangled names.
  415.  
  416.    If there are undefined symbols, GNU ld reports which object file(s)
  417. refer to the undefined symbol(s).
  418.  
  419.    As of binutils version 2.2, on systems that use the so-called "a.out"
  420. debug format (e.g. Suns running SunOS 4.x), the GNU linker compresses
  421. the debug symbol table considerably.
  422.  
  423.    Advantages of collect:
  424.  
  425.    If your native linker supports shared libraries, you can use shared
  426. libraries with collect.  This used to be a strong reason *not* to use
  427. the GNU linker, but recent versions of GNU ld support linking with
  428. shared libraries on many platforms, and creating shared libraries on a
  429. few (such as Intel x86 systems that use ELF object format).
  430.  
  431.    Note: using existing shared libraries (X and libc, for example) works
  432. very nicely.  Generating shared libraries from g++-compiled code is
  433. another matter, generally requiring OS-dependent tricks if it is
  434. possible at all.
  435.  
  436.    However, as of libg++ 2.6.2, the libg++ distribution contains some
  437. experimental patches to build libg++ as a shared library on some OSes.
  438. Check the file `README.SHLIB' from that distribution.
  439.  
  440.    Ron Guilmette has written a set of patches for the g++ compiler that
  441. will permit people using g++ on SVr4 systems (including Solaris) to
  442. build ELF format shared libraries.  These patches ensure that any file
  443. scope static-storage objects within such libraries will be properly
  444. initialized when the libraries are first attached to your running
  445. process.
  446.  
  447.    Ron's patches have been integrated with the 2.6.1 release and the new
  448. patches are available at `ftp.cygnus.com:pub/g++/gcc-2.6.1-shlib.gz'.
  449. These patches will be part of the 2.7.0 release (I believe these
  450. patches will also work if applied to 2.6.3).
  451.  
  452.    The GNU linker has not been ported to as many platforms as g++ has,
  453. so you may be forced to use collect.
  454.  
  455.    If you use collect, you don't need to get something extra and figure
  456. out how to install it; the standard gcc installation procedure will do
  457. it for you.
  458.  
  459.    In conclusion, I don't see a clear win for either alternative at this
  460. point.  Take your pick.
  461.  
  462.  
  463. Should I use the GNU assembler, or my vendor's assembler?
  464. =========================================================
  465.  
  466.    This depends on your platform and your decision about the GNU
  467. linker.  For most platforms, you'll need to use GAS if you use the GNU
  468. linker.  For some platforms, you have no choice; check the gcc
  469. installation notes to see whether you must use GAS.  But you can
  470. usually use the vendor's assembler if you don't use the GNU linker.
  471.  
  472.    The GNU assembler assembles faster than many native assemblers;
  473. however, on many platforms it cannot support the local debugging format.
  474.  
  475.    If you want to build shared libraries from gcc/g++ output and you
  476. are on a Sun, you must *not* use GNU as, as it cannot do
  477. position-independent code correctly yet.
  478.  
  479.    On HPUX or IRIX, you must use GAS (and configure gcc with the
  480. `--with-gnu-as' option) to debug your programs.  GAS is strongly
  481. recommended particularly on the HP platform because of limitations in
  482. the HP assembler.
  483.  
  484.    The GAS distribution has recently been merged with the binutils
  485. distribution, so the GNU assembler and linker are now together in this
  486. package (as of binutils version 2.5.1).
  487.  
  488.  
  489. Should I use the GNU C library?
  490. ===============================
  491.  
  492.    At this point in time, no.  The GNU C library is still very young,
  493. and libg++ still conflicts with it in some places.  Use your native C
  494. library unless you know a lot about the gory details of libg++ and
  495. gnu-libc.  This will probably change in the future.
  496.  
  497.  
  498. Global constructors aren't being called
  499. =======================================
  500.  
  501.    "I've installed gcc and it almost works, but constructors and
  502. destructors for global objects and objects at file scope aren't being
  503. called.  What did I do wrong?"
  504.  
  505.    It appears that you are running on a platform that requires you to
  506. install either "collect2" or the GNU linker, and you have done neither.
  507. For more information, see the section discussing the GNU linker (*Note
  508. use GNU linker?::).
  509.  
  510.    On Solaris 2.x, you shouldn't need a collect program and GNU ld
  511. doesn't run.  If your global constructors aren't being called, you may
  512. need to install a patch, available from Sun, to fix your linker.  The
  513. number of the "jumbo patch" that applies is 101409-03.  Thanks to
  514. Russell Street (r.street@auckland.ac.nz) for this info.
  515.  
  516.    It appears that on IRIX, the collect2 program is not being installed
  517. by default during the installation process, though it is required; you
  518. can install it manually by executing
  519.  
  520.      make install-collect2
  521.  
  522.    from the gcc source directory after installing the compiler.  (I'm
  523. not certain for which versions of gcc this problem occurs, and whether
  524. it is still present).
  525.  
  526.  
  527. Strange assembler errors when linking C++ programs
  528. ==================================================
  529.  
  530.    "I've installed gcc and it seemed to go OK, but when I attempt to
  531. link any C++ program, I'm getting strange errors from the assembler!
  532. How can that be?"
  533.  
  534.    The messages in question might look something like
  535.  
  536.      as: "/usr/tmp/cca14605.s", line 8: error: statement syntax
  537.      as: "/usr/tmp/cca14605.s", line 14: error: statement syntax
  538.  
  539.    (on a Sun, different on other platforms).  The important thing is
  540. that the errors come out at the link step, *not* when a C++ file is
  541. being compiled.
  542.  
  543.    Here's what's going on: the collect2 program uses the Unix "nm"
  544. program to obtain a list of symbols for the global constructors and
  545. destructors, and it builds a little assembly language module that will
  546. permit them all to be called.  If you're seeing this symptom, you have
  547. an old version of GNU nm somewhere on your path.  This old version
  548. prints out symbol names in a format that the collect2 program does not
  549. expect, so bad assembly code is generated.
  550.  
  551.    The solution is either to remove the old version of GNU nm from your
  552. path (and that of everyone else who uses g++), or to install a newer
  553. version (it is part of the GNU "binutils" package).  Recent versions of
  554. GNU nm do not have this problem.
  555.  
  556.  
  557. Problems building libg++ on 386/486
  558. ===================================
  559.  
  560.    Attempts to install libg++ on 386 or 486 systems running ports of
  561. SVR4 have problems because of bugs in debugging support on that
  562. platform.  Briefly, debugging does not currently work right yet for
  563. C++.  You should be able to build the library successfully by deleting
  564. the `-g' flag from the Makefiles (this should no longer be necessary
  565. with gcc 2.4.x although debugging still doesn't work).
  566.  
  567.    See the section entitled "Debugging on SVR4 systems." (*Note
  568. debugging on SVR4 systems::).
  569.  
  570.  
  571. Other problems building libg++
  572. ==============================
  573.  
  574.    "I am having trouble building libg++.  Help!"
  575.  
  576.    On some platforms (for example, Ultrix), you may see errors
  577. complaining about being unable to open dummy.o.  On other platforms
  578. (for example, SunOS), you may see problems having to do with the type
  579. of size_t.  The fix for these problems is to make libg++ by saying
  580. "make CC=gcc".  According to Per Bothner, it should no longer be
  581. necessary to specify "CC=gcc" for libg++-2.3.1 or later.
  582.  
  583.    "I built and installed libg++, but g++ can't find it.  Help!"
  584.  
  585.    The string given to `configure' that identifies your system must be
  586. the same when you install libg++ as it was when you installed gcc.
  587. Also, if you used the `--prefix' option to install gcc somewhere other
  588. than `/usr/local', you must use the same value for `--prefix' when
  589. installing libg++, or else g++ will not be able to find libg++.
  590.  
  591.    The toplevel Makefile in the libg++ 2.6.2 distribution is broken,
  592. which along with a bug in g++ 2.6.3 causes problems linking programs
  593. that use the libstdc++ complex classes.  A patch for this is available
  594. from `ftp.cygnus.com:pub/g++/libg++-2.6.2-fix.gz'.
  595.  
  596.  
  597. But I'm *still* having problems with `size_t'!
  598. ==============================================
  599.  
  600.    "I did all that, and I'm *still* having problems with disagreeing
  601. definitions of size_t, SIZE_TYPE, and the type of functions like
  602. `strlen'."
  603.  
  604.    The problem may be that you have an old version of `_G_config.h'
  605. lying around.  As of libg++ version 2.4, `_G_config.h', since it is
  606. platform-specific, is inserted into a different directory; most include
  607. files are in `$prefix/lib/g++-include', but this file now lives in
  608. `$prefix/$arch/include'.  If, after upgrading your libg++, you find that
  609. there is an old copy of `_G_config.h' left around, remove it, otherwise
  610. g++ will find the old one first.
  611.  
  612.  
  613. Do I need to rebuild libg++ to go with my new g++?
  614. ==================================================
  615.  
  616.    "After I upgraded g++ to the latest version, I'm seeing undefined
  617. symbols."
  618.  
  619.    or
  620.  
  621.    "If I upgrade to a new version of g++, do I need to reinstall
  622. libg++?"
  623.  
  624.    As a rule, the first two digits of your g++ and libg++ should be the
  625. same.  Normally when you do an upgrade in the "minor version number"
  626. (2.5.7 to 2.5.8, say) there isn't a need to rebuild libg++, but there
  627. have been a couple of exceptions in the past.
  628.  
  629.  
  630. User Problems
  631. *************
  632.  
  633.  
  634. gcc 2.5.x broke my code!  Changes in function overloading
  635. =========================================================
  636.  
  637.    "I have a program that worked just fine with older g++ versions, but
  638. as of version 2.5.x it doesn't work anymore.  Help!"
  639.  
  640.    While it's always possible that a new bug has been introduced into
  641. the compiler, it's also possible that you have been relying on bugs in
  642. older versions of g++.  For example, version 2.5.0 was the first
  643. version of g++ to correctly implement the "hiding rule."  That is, if
  644. you have an overloaded function in a base class, and in a derived class
  645. you redefine one of the names, the other names are effectively "hidden".
  646. *All* the names from the baseclass need to be redefined in the derived
  647. class.  See section 13.1 of the ARM: "A function member of a derived
  648. class is *not* in the same scope as a function member of the same name
  649. in a base class".
  650.  
  651.    Here's an example that is handled incorrectly by g++ versions before
  652. 2.5.0 and correctly by newer versions:
  653.  
  654.      class Base {
  655.      public:
  656.          void foo(int);
  657.      };
  658.      
  659.      class Derived : public Base {
  660.      public:
  661.          void foo(double);  // *note that Base::foo(int) is hidden*
  662.      };
  663.      
  664.      main() {
  665.          Derived d;
  666.          d.foo(2); // *Derived::foo(double), not Base::foo(int), is called*
  667.      }
  668.  
  669.  
  670. Where can I find a demangler?
  671. =============================
  672.  
  673.    A g++-compatible demangler named `c++filt' can be found in the
  674. `binutils' distribution.  This distribution (which also contains the
  675. GNU linker) can be found at any GNU archive site.
  676.  
  677.  
  678. Where can I find a version of etags for C++?
  679. ============================================
  680.  
  681.    The libg++ distribution contains a version of etags that works for
  682. C++ code.  Look in `libg++/utils'.  It's not built by default when you
  683. install libg++, but you can cd to that directory and type
  684.  
  685.      make etags
  686.  
  687.    after you've installed libg++.
  688.  
  689.  
  690. Linker reports undefined symbols for static data members
  691. ========================================================
  692.  
  693.    "g++ reports undefined symbols for all my static data members when I
  694. link, even though the program works correctly for compiler XYZ.  What's
  695. going on?"
  696.  
  697.    The problem is almost certainly that you don't give definitions for
  698. your static data members.  If you have
  699.  
  700.      class Foo {
  701.          ...
  702.          void method();
  703.          static int bar;
  704.      };
  705.  
  706.    you have only declared that there is an int named Foo::bar and a
  707. member function named Foo::method that is defined somewhere.  You still
  708. need to defined BOTH method() and bar in some source file.  According
  709. to the draft ANSI standard, you must supply an initializer, such as
  710.  
  711.      int Foo::bar = 0;
  712.  
  713. in one (and only one) source file.
  714.  
  715.  
  716. g++ won't accept the placement new syntax.
  717. ==========================================
  718.  
  719.    "I have a program that uses the "placement syntax" of operator new,
  720. e.g.
  721.  
  722.         new (somewhere) T;
  723.  
  724. and g++ won't accept it."
  725.  
  726.    You must have a very old version of g++; everything since 2.3.1
  727. accepts placement new correctly.  The only remaining problems were with
  728. declarators for pointers to functions:
  729.  
  730.      new (void (*)(int));  // confuses gcc 2.3.2, some versions dump core (2.5.8)
  731.      new (a) (void (*)(int)); // ditto
  732.  
  733.    Even these work correctly with 2.6.0.  For older versions, these can
  734. be worked around with a typedef:
  735.  
  736.      typedef void (*fun)(int);
  737.      new fun;
  738.      new (a) fun;
  739.  
  740.  
  741. Overloaded increment (`++') and decrement (`--') operators
  742. ==========================================================
  743.  
  744.    "g++ doesn't seem to distinguish the prefix and postfix forms of
  745. `operator++'.  What gives?"
  746.  
  747.    Again, you must have a very old g++ to have this problem.  The
  748. solution is to upgrade your compiler; distinguishing the prefix and
  749. postfix cases of `operator++' and `operator--' was first implemented in
  750. g++ version 2.4.1.
  751.  
  752.    For backward compatibility, if a class declares a prefix version of
  753. `operator++' (or `operator--') but no postfix version, and code
  754. attempts to use `++' (or `--') as a postfix operator, g++ will use the
  755. prefix version (unless the `-pedantic' flag is set).  This feature is
  756. to avoid breaking old code.
  757.  
  758.  
  759. What does "Internal compiler error" mean?
  760. =========================================
  761.  
  762.    It means that the compiler has detected a bug in itself.
  763. Unfortunately, g++ still has many bugs.  If you see this message,
  764. please send in a complete bug report (see next section).
  765.  
  766.  
  767. I think I have found a bug in g++.
  768. ==================================
  769.  
  770.    "I think I have found a bug in g++, but I'm not sure.  How do I know,
  771. and who should I tell?"
  772.  
  773.    First, see the excellent section on bugs and bug reports in the gcc
  774. manual (which is included in the gcc distribution).  As a short summary
  775. of that section: if the compiler gets a fatal signal, for any input,
  776. it's a bug (newer versions of g++ will ask you to send in a bug report
  777. when they detect an error in themselves).  Same thing for producing
  778. invalid assembly code.
  779.  
  780.    When you report a bug, make sure to describe your platform (the type
  781. of computer, and the version of the operating system it is running) and
  782. the version of the compiler that you are running.  See the output of the
  783. command `g++ -v' if you aren't sure.  Also provide enough code so that
  784. the g++ maintainers can duplicate your bug.  Remember that the
  785. maintainers won't have your header files; one possibility is to send
  786. the output of the preprocessor (use `g++ -E' to get this).  This is
  787. what a "complete bug report" means.
  788.  
  789.    I will add some extra notes that are C++-specific, since the notes
  790. from the gcc documentation are generally C-specific.
  791.  
  792.    First, mail your bug report to "bug-g++@prep.ai.mit.edu".  You may
  793. also post to gnu.g++.bug, but it's better to use mail, particularly if
  794. you have any doubt as to whether your news software generates correct
  795. reply addresses.  Don't mail C++ bugs to bug-gcc@prep.ai.mit.edu.
  796.  
  797.    If your bug involves libg++ rather than the compiler, mail to
  798. bug-lib-g++@prep.ai.mit.edu.  If you're not sure, choose one, and if you
  799. guessed wrong, the maintainers will forward it to the other list.
  800.  
  801.    Second, if your program does one thing, and you think it should do
  802. something else, it is best to consult a good reference if in doubt.  The
  803. standard reference is "The Annotated C++ Reference Manual", by Ellis and
  804. Stroustrup (copyright 1990, ISBN #0-201-51459-1).  This is what they're
  805. talking about on the net when they refer to "the ARM".
  806.  
  807.    The reference manual, without annotations, also appears in
  808. Stroustrup's "The C++ Programming Language, Second Edition" (copyright
  809. 1991, ISBN #0-201-53992-6).  Both books are published by Addison-Wesley.
  810.  
  811.    The ANSI/ISO C++ standards committee have adopted some changes to the
  812. C++ language since the publication of the original ARM, and newer
  813. versions of g++ (2.5.x and later) support some of these changes, notably
  814. the mutable keyword (added in 2.5.0) and the bool type (added in 2.6.0).
  815. You can obtain an addendum to the ARM explaining these changes by FTP
  816. from ftp.std.com in `/AW/stroustrup2e/iso.ps'.
  817.  
  818.    Note that the behavior of (any version of) AT&T's "cfront" compiler
  819. is NOT the standard for the language.
  820.  
  821.  
  822. Porting programs from other compilers to g++
  823. ============================================
  824.  
  825.    "I have a program that runs on <some other C++ compiler>, and I want
  826. to get it running under g++.  Is there anything I should watch out for?"
  827.  
  828.    First, see the questions on placement new syntax and static data
  829. members.
  830.  
  831.    Secondly, if the porting problem relates to the resolution of
  832. overloaded operators or functions, and you're running g++ 2.5.x, you
  833. might try the `-fansi-overloading' switch.  This switch is obsolete in
  834. 2.6.0 or later, since the `-fansi-overloading' code is now the default.
  835. This switch enables new code that attempts to match the ARM
  836. specification of overloaded argument resolution better.
  837.  
  838.    There are two other reasons why a program that worked under one
  839. compiler might fail under another: your program may depend on the order
  840. of evaluation of side effects in an expression, or it may depend on the
  841. lifetime of a temporary (you may be assuming that a temporary object
  842. "lives" longer than the standard guarantees).  As an example of the
  843. first:
  844.  
  845.      void func(int,int);
  846.      
  847.      int i = 3;
  848.      func(i++,i++);
  849.  
  850.    Novice programmers think that the increments will be evaluated in
  851. strict left-to-right order.  Neither C nor C++ guarantees this; the
  852. second increment might happen first, for example.  func might get 3,4,
  853. or it might get 4,3.
  854.  
  855.    The second problem often happens with classes like the libg++ String
  856. class.  Let's say I have
  857.  
  858.      String func1();
  859.      void func2(const char*);
  860.  
  861.    and I say
  862.  
  863.      func2(func1());
  864.  
  865.    because I know that class String has an "operator const char*".  So
  866. what really happens is
  867.  
  868.      func2(func1().convert());
  869.  
  870.    where I'm pretending I have a convert() method that is the same as
  871. the cast.  This is unsafe in g++ versions before 2.6.0, because the
  872. temporary String object may be deleted after its last use (the call to
  873. the conversion function), leaving the pointer pointing to garbage, so by
  874. the time func2 is called, it gets an invalid argument.
  875.  
  876.    Both the cfront and the old g++ behaviors are legal according to the
  877. ARM, but the powers that be have decided that compiler writers were
  878. given too much freedom here.
  879.  
  880.    The ANSI C++ committee has now come to a resolution of the lifetime
  881. of temporaries problem: they specify that temporaries should be deleted
  882. at end-of-statement (and at a couple of other points).  This means that
  883. g++ versions before 2.6.0 now delete temporaries too early, and cfront
  884. deletes temporaries too late.  As of version 2.6.0, g++ does things
  885. according to the new standard.
  886.  
  887.    For now, the safe way to write such code is to give the temporary a
  888. name, which forces it to live until the end of the scope of the name.
  889. For example:
  890.  
  891.      String& tmp = func1();
  892.      func2(tmp);
  893.  
  894.    Finally, like all compilers (but especially C++ compilers, it seems),
  895. g++ has bugs, and you may have tweaked one.  If so, please file a bug
  896. report (after checking the above issues).
  897.  
  898.  
  899. Why does g++ mangle names differently from other C++ compilers?
  900. ===============================================================
  901.  
  902.    See the answer to the next question.
  903.  
  904.  
  905. Why can't g++ code link with code from other C++ compilers?
  906. ===========================================================
  907.  
  908.    "Why can't I link g++-compiled programs against libraries compiled by
  909. some other C++ compiler?"
  910.  
  911.    Some people think that, if only the FSF and Cygnus Support folks
  912. would stop being stubborn and mangle names the same way that, say,
  913. cfront does, then any g++-compiled program would link successfully
  914. against any cfront-compiled library and vice versa.  Name mangling is
  915. the least of the problems.  Compilers differ as to how objects are laid
  916. out, how multiple inheritance is implemented, how virtual function
  917. calls are handled, and so on, so if the name mangling were made the
  918. same, your programs would link against libraries provided from other
  919. compilers but then crash when run.  For this reason, the ARM
  920. *encourages* compiler writers to make their name mangling different
  921. from that of other compilers for the same platform.  Incompatible
  922. libraries are then detected at link time, rather than at run time.
  923.  
  924.  
  925. What documentation exists for g++ 2.x?
  926. ======================================
  927.  
  928.    Relatively little.  While the gcc manual that comes with the
  929. distribution has some coverage of the C++ part of the compiler, it
  930. focuses mainly on the C compiler (though the information on the "back
  931. end" pertains to C++ as well).  Still, there is useful information on
  932. the command line options and the #pragma interface and #pragma
  933. implementation directives in the manual, and there is a useful section
  934. on template instantiation in the 2.6 version.  There is a Unix-style
  935. manual entry, "g++.1", in the gcc-2.x distribution; the information
  936. here is a subset of what is in the manual.
  937.  
  938.    You can buy a nicely printed and bound copy of this manual from the
  939. FSF; see above for ordering information.
  940.  
  941.    For versions 2.6.2 and later, the gcc/g++ distribution contains the
  942. gcc manual in PostScript.  Also, Postscript versions of GNU
  943. documentation in U.S. letter format are available by anonymous FTP to
  944. primus.com in /pub/gnu-ps.  The same, in A4 format, are on
  945. liasun3.epfl.ch in /pub/gnu/ps-doc.
  946.  
  947.    A draft of a document describing the g++ internals appears in the gcc
  948. distribution (called g++int.texi); it is still incomplete.
  949.  
  950.  
  951. Problems with the template implementation
  952. =========================================
  953.  
  954.    The template implementation is still new.  The implementation in
  955. 2.5.x represents a considerable improvement over that of previous
  956. releases, but it has a long way to go.  This continues to improve from
  957. release to release.
  958.  
  959.    g++ does not implement a separate pass to instantiate template
  960. functions and classes at this point; for this reason, it will not work,
  961. for the most part, to declare your template functions in one file and
  962. define them in another.  The compiler will need to see the entire
  963. definition of the function, and will generate a static copy of the
  964. function in each file in which it is used.
  965.  
  966.    For version 2.6.0, however, a new switch `-fno-implicit-templates'
  967. was added; with this switch, templates are expanded only under user
  968. control.  I recommend that all g++ users that use templates read the
  969. section "Template Instantiation" in the gcc manual (version 2.6.x and
  970. newer).  g++ now supports explicit template expansion using the syntax
  971. from the latest C++ working paper:
  972.  
  973.      template class A<int>;
  974.      template ostream& operator << (ostream&, const A<int>&);
  975.  
  976.    As of version 2.6.3, there are still a few limitations in the
  977. template implementation besides the above (thanks to Jason Merrill for
  978. this info):
  979.  
  980.   1. Static data member templates are not supported.  You can work
  981.      around this by explicitly declaring the static variable for each
  982.      template specialization:
  983.  
  984.           template <class T> struct A {
  985.             static T t;
  986.           };
  987.           
  988.           template <class T> T A<T>::t = 0; // gets bogus error
  989.           int A<int>::t = 0;                // OK (workaround)
  990.  
  991.   2. Template member names are not available when defining member
  992.      function templates.
  993.  
  994.           template <class T> struct A {
  995.             typedef T foo;
  996.             void f (foo);
  997.             void g (foo arg) { ... }; // this works
  998.           };
  999.           
  1000.           template <class T> void A<T>::f (foo) { } // gets bogus error
  1001.  
  1002.   3. Templates are instantiated using the parser.  This results in two
  1003.      problems:
  1004.  
  1005.      a) Class templates are instantiated in some situations where such
  1006.      instantiation should not occur.
  1007.  
  1008.           template <class T> class A { };
  1009.           A<int> *aip = 0; // should not instantiate A<int> (but does)
  1010.  
  1011.      b) Function templates cannot be inlined at the site of their
  1012.      instantiation.
  1013.  
  1014.           template <class T> inline T min (T a, T b) { return a < b ? a : b; }
  1015.           
  1016.           void f () {
  1017.             int i = min (1, 0);           // not inlined
  1018.           }
  1019.           
  1020.           void g () {
  1021.             int j = min (1, 0);           // inlined
  1022.           }
  1023.  
  1024.      A workaround that works in version 2.6.1 and later is to specify
  1025.  
  1026.           extern template int min (int, int);
  1027.  
  1028.      before `f()'; this will force it to be instantiated (though not
  1029.      emitted).
  1030.  
  1031.   4. Member function templates are always instantiated when their
  1032.      containing class is.  This is wrong.
  1033.  
  1034.  
  1035. I get undefined symbols when using templates
  1036. ============================================
  1037.  
  1038.    (Thanks to Jason Merrill for this section).
  1039.  
  1040.    g++ does not automatically instantiate templates defined in other
  1041. files.  Because of this, code written for cfront will often produce
  1042. undefined symbol errors when compiled with g++.  You need to tell g++
  1043. which template instances you want, by explicitly instantiating them in
  1044. the file where they are defined.  For instance, given the files
  1045.  
  1046.    `templates.h':
  1047.      template <class T>
  1048.      class A {
  1049.      public:
  1050.        void f ();
  1051.        T t;
  1052.      };
  1053.      
  1054.      template <class T> void g (T a);
  1055.  
  1056.    `templates.cc':
  1057.      #include "templates.h"
  1058.      
  1059.      template <class T>
  1060.      void A::f () { }
  1061.      
  1062.      template <class T>
  1063.      void g (T a) { }
  1064.  
  1065.    main.cc:
  1066.      #include "templates.h"
  1067.      
  1068.      main ()
  1069.      {
  1070.        A<int> a;
  1071.        a.f ();
  1072.        g (a);
  1073.      }
  1074.  
  1075.    compiling everything with `g++ main.cc templates.cc' will result in
  1076. undefined symbol errors for `A<int>::f ()' and `g (A<int>)'.  To fix
  1077. these errors, add the lines
  1078.  
  1079.      template class A<int>;
  1080.      template void g (A<int>);
  1081.  
  1082.    to the bottom of `templates.cc' and recompile.
  1083.  
  1084.  
  1085. I get multiply defined symbols using templates
  1086. ==============================================
  1087.  
  1088.    You may be running into a bug that was introduced in version 2.6.1
  1089. (and is still present in 2.6.3) that generated external linkage for
  1090. templates even when neither `-fexternal-templates' nor
  1091. `-fno-implicit-templates' is specified.  There is a patch for this
  1092. problem at ftp.cygnus.com:pub/g++/gcc-2.6.3-template-fix.  I recommend
  1093. either applying the patch or using `-fno-implicit-templates' together
  1094. with explicit template instantiation as described in previous sections.
  1095.  
  1096.  
  1097. Does g++ support the Standard Template Library?
  1098. ===============================================
  1099.  
  1100.    From Per Bothner:
  1101.  
  1102.    The Standard Template Library (STL) uses many of the extensions that
  1103. the ANSI/ISO committee has made to templates, and g++ doesn't support
  1104. some of these yet.  So if you grab HP's free implementation of STL it
  1105. isn't going to work.  However, libg++-2.6.2 contains a hacked version
  1106. of STL, based on work by Carsten Bormann, which permits gcc-2.6.3 to
  1107. compile at least the containers.  A full implementation is going to
  1108. need improved template support, which will take a while yet.
  1109.  
  1110.  
  1111. What are the differences between g++ and the ARM specification of C++?
  1112. ======================================================================
  1113.  
  1114.    The chief thing missing from g++ that is in the ARM is exceptions.
  1115. There is an alpha version of exceptions in version 2.6.1 for SunOS4 on
  1116. the Sparc, but not for other platforms.  Patches to g++ to enable
  1117. exception handling for the Intel x86 and RS/6000 platforms are
  1118. available from Mike Stump's World Wide Web home page:
  1119. `http://www.cygnus.com/~mrs/'.
  1120.  
  1121.    Some features that the ANSI/ISO standardization committee has voted
  1122. in that don't appear in the ARM are supported, notably the `mutable'
  1123. keyword, in version 2.5.x.  2.6.x adds support for the built-in boolean
  1124. type `bool', with constants `true' and `false'.  The beginnings of
  1125. run-time type identification are present, so there are more reserved
  1126. words: `typeid', `static_cast', `reinterpret_cast', `const_cast', and
  1127. `dynamic_cast'.
  1128.  
  1129.    As with any beta-test compiler, there are bugs.  You can help improve
  1130. the compiler by submitting detailed bug reports.
  1131.  
  1132.    One of the weakest areas of g++ other than templates is the
  1133. resolution of overloaded functions and operators in complex cases.  The
  1134. usual symptom is that in a case where the ARM says that it is ambiguous
  1135. which function should be chosen, g++ chooses one (often the first one
  1136. declared).  This is usually not a problem when porting C++ code from
  1137. other compilers to g++, but shows up as errors when code developed under
  1138. g++ is ported to other compilers.
  1139.  
  1140.    As of 2.5.0, the overloading code has been rewritten.  For now, you
  1141. must specify the option `-fansi-overloading' to get the new code, since
  1142. there were some important users actually depending on g++'s incorrect
  1143. resolution of ambiguities.  This switch should disappear in the future.
  1144. If a program that compiled under previous g++ versions now reports that
  1145. a use of an overloaded function is ambiguous, it is likely that the old
  1146. g++ was letting you write buggy code and the new one is detecting the
  1147. problem.  If in doubt, consult the ARM.
  1148.  
  1149.    [A full bug list would be very long indeed, so I won't put one here.
  1150. I may add a list of frequently-reported bugs and "non-bugs" like the
  1151. static class members issue mentioned above].
  1152.  
  1153.  
  1154. Will g++ compile InterViews?  The NIH class library?
  1155. ====================================================
  1156.  
  1157.    The NIH class library uses a non-portable, compiler-dependent hack
  1158. to initialize itself, which makes life difficult for g++ users.  It
  1159. will not work without modification, and I don't know what modifications
  1160. are required or whether anyone has done them successfully.
  1161.  
  1162.    In short, it's not going to happen any time soon (previous FAQs
  1163. referred to patches that a new NIHCL release would hopefully contain,
  1164. but this hasn't happened).
  1165.  
  1166.    [ From Steinar Bang <steinarb@idt.unit.no>]
  1167.  
  1168.    InterViews 3.1 compiles and runs with gcc-2.3.3 and libg++-2.3,
  1169. except that the "doc" application immediately dumps core when you try
  1170. to run it.  There is also a small glitch with idraw.
  1171.  
  1172.    There is a patch for InterViews 3.1 from Johan Garpendahl
  1173. <garp@isy.liu.se> available for FTP from site "ugle.unit.no".  It is in
  1174. the file
  1175.  
  1176.    `/pub/X11/contrib/InterViews/g++/3.1-beta3-patch'.
  1177.  
  1178.    This fixes two things: the Doc coredump, and the pattern menu of
  1179. idraw.  Read the instructions at the start of the file.
  1180.  
  1181.    I think that as of version 2.5.6, the standard g++ will compile the
  1182. standard 3.1 InterViews completely successfully.  I'd appreciate a
  1183. confirmation.
  1184.  
  1185.  
  1186. Debugging on SVR4 systems
  1187. =========================
  1188.  
  1189.    "When I use the `-g' flag on C++ code on a System V Release 4 system,
  1190. I get lots of undefined symbols at link time.  Why?  Help!"
  1191.  
  1192.    Most systems based on System V Release 4 (except Solaris) encode
  1193. symbolic debugging information in a format known as `DWARF'.
  1194.  
  1195.    Although the GNU C compiler already knows how to write out symbolic
  1196. debugging information in the DWARF format, the GNU C++ compiler does
  1197. not yet have this feature, nor is it likely to in the immediate future.
  1198.  
  1199.    Ron Guilmette has done a great deal of work to try to get the GNU
  1200. C++ compiler to produce DWARF format symbolic debugging information
  1201. (for C++ code) but he gave up on the project because of a lack of
  1202. funding and/or interest from the g++ user community.  If you have a
  1203. strong desire to see this project completed, contact Ron at
  1204. <rfg@netcom.com>.
  1205.  
  1206.    In the meantime, you *can* get g++ debugging under SVR4 systems by
  1207. configuring gcc with the `--with-stabs' option.  This causes gcc to use
  1208. an alternate debugging format, one more like that used under SunOS4.
  1209. You won't need to do anything special to GDB; it will always understand
  1210. the "stabs" format.
  1211.  
  1212.  
  1213. X11 conflicts with libg++ in definition of String
  1214. =================================================
  1215.  
  1216.    "X11 and Motif define String, and this conflicts with the String
  1217. class in libg++.  How can I use both together?"
  1218.  
  1219.    One possible method is the following:
  1220.  
  1221.      #define String XString
  1222.      #include <X11/Intrinsic.h>
  1223.      /* include other X11 and Motif headers */
  1224.      #undef String
  1225.  
  1226.    and remember to use the correct `String' or `XString' when you
  1227. declare things later.
  1228.  
  1229.  
  1230. Why can't I assign one stream to another?
  1231. =========================================
  1232.  
  1233.    [ Thanks to Per Bothner and Jerry Schwarz for this section. ]
  1234.  
  1235.    Assigning one stream to another seems like a reasonable thing to do,
  1236. but it's a bad idea.  Usually, this comes up because people want to
  1237. assign to `cout'.  This is poor style, especially for libraries, and is
  1238. contrary to good object-oriented design.  (Libraries that write directly
  1239. to `cout' are less flexible, modular, and object-oriented).
  1240.  
  1241.    The iostream classes do not allow assigning to arbitrary streams,
  1242. because this can violate typing:
  1243.  
  1244.      ifstream foo ("foo");
  1245.      istrstream str(...);
  1246.      foo = str;
  1247.      foo->close ();  /* Oops! Not defined for istrstream! */
  1248.  
  1249.    The original cfront implementation of iostreams by Jerry Schwarz
  1250. allows you to assign to `cin', `cout', `cerr', and `clog', but this is
  1251. not part of the draft standard for iostreams and generally isn't
  1252. considered a good idea, so standard-conforming code shouldn't use this
  1253. technique.
  1254.  
  1255.    The GNU implementation of iostream did not support assigning to
  1256. `cin', `cout', `cerr', and `clog' for quite a while, but it now does,
  1257. for backward compatibility with cfront iostream (versions 2.6.1 and
  1258. later of libg++).
  1259.  
  1260.    The ANSI/ISO C++ Working Paper does provide ways of changing the
  1261. streambuf associated with a stream.  Assignment isn't allowed; there is
  1262. an explicit named member that must be used.
  1263.  
  1264.    However, it is not wise to do this, and the results are confusing.
  1265. For example: `fstream::rdbuf' is supposed to return the *original*
  1266. filebuf, not the one you assigned. (This is not yet implemented in GNU
  1267. iostream.)  This must be so because `fstream::rdbuf' is defined to
  1268. return a `filebuf *'.
  1269.  
  1270.  
  1271. What are the rules for shipping code built with g++ and libg++?
  1272. ***************************************************************
  1273.  
  1274.    "Is it is possible to distribute programs for profit that are created
  1275. with g++ and use the g++ libraries?"
  1276.  
  1277.    I am not a lawyer, and this is not legal advice.  In any case, I have
  1278. little interest in telling people how to violate the spirit of the GNU
  1279. licenses without violating the letter.  This section tells you how to
  1280. comply with the intention of the GNU licenses as best I understand them.
  1281.  
  1282.    The FSF has no objection to your making money.  Its only interest is
  1283. that source code to their programs, and libraries, and to modified
  1284. versions of their programs and libraries, is always available.
  1285.  
  1286.    The short answer is that you do not need to release the source to
  1287. your program, but you can't just ship a stripped executable either,
  1288. unless you use only the subset of libg++ that includes the iostreams
  1289. classes (see discussion below) or the new libstdc++ library (available
  1290. in libg++ 2.6.2 and later).
  1291.  
  1292.    Compiling your code with a GNU compiler does not affect its
  1293. copyright; it is still yours.  However, in order to ship code that
  1294. links in a GNU library such as libg++ there are certain rules you must
  1295. follow.  The rules are described in the file COPYING.LIB that
  1296. accompanies gcc distributions; it is also included in the libg++
  1297. distribution.  See that file for the exact rules.  The agreement is
  1298. called the Library GNU Public License or LGPL.  It is much "looser"
  1299. than the GNU Public License, or GPL, that covers must GNU programs.
  1300.  
  1301.    Here's the deal: let's say that you use some version of libg++,
  1302. completely unchanged, in your software, and you want to ship only a
  1303. binary form of your code.  You can do this, but there are several
  1304. special requirements.  If you want to use libg++ but ship only object
  1305. code for your code, you have to ship source for libg++ (or ensure
  1306. somehow that your customer already has the source for the exact version
  1307. you are using), and ship your application in linkable form.  You cannot
  1308. forbid your customer from reverse-engineering or extending your program
  1309. by exploiting its linkable form.
  1310.  
  1311.    Furthermore, if you modify libg++ itself, you must provide source
  1312. for your modifications (making a derived class does not count as
  1313. modifying the library - that is "a work that uses the library").
  1314.  
  1315.    For certain portions of libg++ that implement required parts of the
  1316. C++ language (such as iostreams), the FSF has loosened the copyright
  1317. requirement still more by adding the "special exception" clause, which
  1318. reads as follows:
  1319.  
  1320.      As a special exception, if you link this library with files
  1321.      compiled with GCC to produce an executable, this does not cause
  1322.      the resulting executable to be covered by the GNU General Public
  1323.      License.  This exception does not however invalidate any other
  1324.      reasons why the executable file might be covered by the GNU
  1325.      General Public License.
  1326.  
  1327.    If your only use of libg++ uses code with this exception, you may
  1328. ship stripped executables or license your executables under different
  1329. conditions without fear of violating an FSF copyright.  It is the intent
  1330. of FSF and Cygnus that, as the other classes required by the ANSI/ISO
  1331. draft standard are developed, these will also be placed under this
  1332. "special exception" license.  The code in the new libstdc++ library,
  1333. intended to implement standard classes as defined by ANSI/ISO, is also
  1334. licensed this way.
  1335.  
  1336.    To avoid coming under the influence of the LGPL, you can link with
  1337. `-liostream' rather than `-lg++'.  You can also use `-lstdc++' now that
  1338. it is available.
  1339.  
  1340.  
  1341. Concept Index
  1342. *************
  1343.  
  1344. -- 
  1345. -- Joe Buck     <jbuck@synopsys.com>    (not speaking for Synopsys, Inc)
  1346. Phone: +1 415 694 1729
  1347.